@extends('admin.formLayout')
@if(isset($id))
    @section('title','编辑广告')
@section('barName','编辑广告')
@else
    @section('title','添加广告')
@section('barName','添加广告')
@endif
@section('content')
    <form class="layui-form" @if(!isset($id)) action="{{route('admin.adseat-add')}}" @else action="{{route('admin.adseat-edit',['id'=>$id])}}" @endif method="post">
        <div class="layui-tab" lay-filter="posts">
            <ul class="layui-tab-title">
                <li class="layui-this">基本信息</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <div class="layui-row">
                            <div class="layui-col-md8">
                                {{csrf_field()}}
                                @if(isset($id))
                                    <input type="hidden" name="id" value="{{$id}}">
                                @endif
                                <div class="layui-form-item">
                                    <label class="layui-form-label">标题<span style="color:red">*</span></label>
                                    <div class="layui-input-block">
                                        <input type="text" name="title" lay-verify="required"  value="@if(old('title')){{old('title')}}@else{{$model->title or ''}}@endif" autocomplete="off" placeholder="请输入标题" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">排序</label>
                                    <div class="layui-input-block">
                                        <input type="number" name="sort" value="@if(old('sort')){{old('sort')}}@else{{$model->sort or ''}}@endif"  class="layui-input" placeholder="请填写整数,值越小文章越靠前。">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">链接<span style="color:red">*</span></label>
                                    <div class="layui-input-block">
                                        <input type="text" name="link"   value="@if(old('link')){{old('link')}}@else{{$model->link or ''}}@endif" autocomplete="off" placeholder="请带上http://或https://，例http://www.baidu.com" class="layui-input" lay-verify="required" >
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md4">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">状态<span >(默认为不展示)</span></label>
                                    <div class="layui-input-block">
                                        @foreach($status as $k=>$v)
                                            <input type="radio" name="status" value="{{$k}}" title="{{$v}}" @if(old('status')) {{$k==old('status')?'checked':''}} @else @if(isset($model->status) && $v==$model->status) checked @endif @endif />
                                        @endforeach
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">图片<span style="color:red">*</span></label>
                                    <div class="layui-input-block">
                                        @php
                                            if(old('img')){
                                                $imgUrl = old('img');
                                            }
                                            else{
                                                $imgUrl = isset($model->img) ? $model->img : '';
                                            }
                                        @endphp
                                        @include('admin.form.image',['name'=>'img','value'=>$imgUrl])
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" lay-submit="" lay-filter="form">立即提交</button>
                                    <button type="button"  onclick="javascript:location.href='{{route('admin.adseat')}}'" class="layui-btn layui-btn-primary">返回</button>
                                </div>
                            </div>
                    </div>
                </div>
            </div>
        </div>

    </form>
@endsection
@section('script')

    <script>
        layui.use(['element','form','layer','upload'], function(){
            var element = layui.element;
            var form = layui.form;
            var layer = layui.layer;
            var upload = layui.upload;
            form.on('submit(*)',function(data){
                console.log(data);
                return false;
            });
            //一些事件监听
            element.on('tab(posts)', function(data){
            });
            @if (count($errors) > 0)
                @foreach ($errors->all() as $error)
                    layer.msg('{{$error}}',{'icon':2});
                    @break
                @endforeach
            @endif

        });
    </script>
@endsection